<?php

include("../../config.php");
include_once(DAO."/AdminDAO.php");
new Conexao;

$admin = AdminDAO::buscaPorId($_REQUEST['id']);

if(isset($_POST['ok'])) {
    $admin->setSenha($_POST['senha']);
    if(AdminDAO::alterar($admin)) {
        $ok = true;
    }
    else {
        $erro = "Falha ao editar senha";
    }
}

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <script src="<?=URL;?>/gui/js/jquery-1.3.2.min.js" type="text/javascript"></script>
        <script src="<?=URL;?>/gui/js/jquery.blockUI.js" type="text/javascript"></script>
        <script src="<?=URL;?>/gui/js/admin.js" type="text/javascript"></script>
        <link href="<?=URL;?>/gui/css/popup.css" rel="stylesheet" type="text/css" />
        <title>:: ComprasWeb ::</title>
        <?php if(isset($erro) || isset($ok)) { ?>
        <script type="text/javascript">
    <?php if(isset($ok)) { ?>
        fechar("OK","Alterado com sucesso!");
        <?php } else { ?>
            $(document).ready(function(){
                window.parent.mensagem("Erro","<?=$erro;?>");
            });
        <?php } ?>
        </script>
        <?php } ?>
    </head>
    <body>
        <form method="post" onsubmit="return validarAdm();">
            <input type="hidden" id="id" name="id" value="<?=$admin->getId();?>" />
            <table>
                <tr>
                    <td>Admin:</td>
                    <td><?=$admin->getNome();?></td>
                </tr>
                <tr>
                    <td>Senha:</td>
                    <td>
                        <input id="senha" name="senha" readonly value="" />
                        <img src="<?=URL;?>/gui/css/images/lock_add.png" alt="Gerar Senha" title="Gerar Senha" onClick="gerarSenha('#senha');" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input name="ok" value="Salvar" type="submit" />
                        <input type="button" value="Fechar" onclick="fechar();" />
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>